package org.artifact.core.lang;

import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.io.resource.UrlResource;
import cn.hutool.setting.Setting;
import org.artifact.core.context.bytebuf.ArrayByteBuffFactory;
import org.artifact.core.context.bytebuf.IByteBuffFactory;
import org.artifact.core.context.id.IDFactory;
import org.artifact.core.context.json.FastJsonFactory;
import org.artifact.core.context.json.IJsonFactory;
import org.artifact.core.context.packet.IPacketFactory;
import org.artifact.core.context.packet.SimplePacketFactory;
import org.artifact.core.context.session.ISessionFactory;
import org.yaml.snakeyaml.Yaml;

import cn.hutool.core.io.FileUtil;
import lombok.Data;

@SuppressWarnings("rawtypes")
@Data
public final class IContext {
	private Map config = new LinkedHashMap<>();

	private IJsonFactory jsonFactory;
	
	private IPacketFactory packetFactory;
	
	private ISessionFactory sessionFactory;
	
	private IByteBuffFactory byteBuffFactory;

	private IDFactory idFactory;

	public IContext() {
		// 加载默认配置文件
		URL url = ResourceUtil.getResourceObj("default.yml").getUrl();
		UrlResource urlResource = new UrlResource(url);
		Map conf = new Yaml().loadAs(urlResource.getStream(), Map.class);
		MapPlus.merge(config, conf);
		
		jsonFactory = new FastJsonFactory();
		
		packetFactory = new SimplePacketFactory();
		
		byteBuffFactory = new ArrayByteBuffFactory();
	}
	
	
//	/**
//	 * Spring上下文
//	 * new FileSystemXmlApplicationContext(path);
//	 * new ClassPathXmlApplicationContext(path);
//	 */
//	private ApplicationContext springContext;
}
